package cn.weblog.api.controller;

import cn.weblog.api.service.KeywordService;
import cn.weblog.api.service.PassageService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/keyword")
@ResponseBody
public class KeywordController {

	@Autowired
	private KeywordService keywordService;

	@Autowired
	private PassageService passageService;

	@RequestMapping("/findPassage/{id}")	//t 查询关键词，查询关键词对应文章
	public String findPassage(@PathVariable Integer id){
		Map<String,Object> result=new HashMap<>();
		//result.put("currentKId",id);
		//result.put("keywords",keywordService.findTop10());		// 没必要？
		result.put("kPassages",passageService.findByKeyword(id));
		return JSON.toJSONString(result);
	}
}
